package pingan.com.quarter_hour.acyivity.login;

import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.TextView;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import pingan.com.quarter_hour.R;
import pingan.com.quarter_hour.acyivity.WriteFinishActivity;
import pingan.com.quarter_hour.utils.BaseActivity;

public class WriteJokeActivity extends BaseActivity implements View.OnClickListener {

    @BindView(R.id.finish)
    TextView finish;
    @BindView(R.id.ed_text)
    EditText edText;
    @BindView(R.id.back)
    LinearLayout back;
    @BindView(R.id.writeover)
    TextView writeover;
    private PopupWindow mPopWindow;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_write_joke);
        ButterKnife.bind(this);

    }

    @OnClick({R.id.finish,R.id.writeover})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.finish:
                showPopWindow();
                back.setBackgroundColor(getResources().getColor(R.color.colorhui));
                break;

            case R.id.writeover:
                showPopWindow();
                back.setBackgroundColor(getResources().getColor(R.color.colorhui));
                break;
        }
    }

    private void showPopWindow() {
        View contentView = LayoutInflater.from(WriteJokeActivity.this).inflate(R.layout.popitem, null);
        mPopWindow = new PopupWindow(contentView, RecyclerView.LayoutParams.WRAP_CONTENT, RecyclerView.LayoutParams.WRAP_CONTENT, true);

        TextView tv1 = (TextView) contentView.findViewById(R.id.pop_yes);
        TextView tv2 = (TextView) contentView.findViewById(R.id.pop_no);
        TextView tv3 = (TextView) contentView.findViewById(R.id.pop_bey);
        tv1.setOnClickListener(this);
        tv2.setOnClickListener(this);
        tv3.setOnClickListener(this);

        //显示
        View rootview = LayoutInflater.from(WriteJokeActivity.this).inflate(R.layout.activity_main, null);
        mPopWindow.showAtLocation(rootview, Gravity.BOTTOM, 0, 0);
    }

    //pop的点击事件
    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.pop_yes:
                stopPopWindow();
                back.setBackgroundColor(Color.WHITE);

                Intent intent = new Intent(WriteJokeActivity.this, WriteFinishActivity.class);
                startActivity(intent);
                finish();
                break;
            case R.id.pop_no:
                stopPopWindow();
                back.setBackgroundColor(Color.WHITE);
                break;
            case R.id.pop_bey:
                stopPopWindow();
                back.setBackgroundColor(Color.WHITE);
                break;
        }
    }

    public void stopPopWindow() {
        if (mPopWindow.isShowing()) {
            mPopWindow.dismiss();
        }
    }
}
